#include "Textures/Sampler.h"
#ifndef I_TEXTURE
#define I_TEXTURE
namespace gname
{
	
	
	enum TextureCreationType
	{
		Tex2D,
		Tex3D,
		CubeTexture,
		RenderTarget
	};

	enum TexType
	{
	TTYPE_BYTE                      =     0x1400,
	TTYPE_UNSIGNED_BYTE             =     0x1401,
	TTYPE_SHORT                     =     0x1402,
	TTYPE_UNSIGNED_SHORT            =     0x1403,
	TTYPE_INT                       =     0x1404,
	TTYPE_UNSIGNED_INT              =     0x1405,
	TTYPE_FLOAT                     =     0x1406,
	TTYPE_2_BYTES                   =     0x1407,
	TTYPE_3_BYTES                   =     0x1408,
	TTYPE_4_BYTES                   =     0x1409,
	TTYPE_DOUBLE                    =     0x140A,
	TTYPE_HALF_FLOAT				=	  0x140B
	};
	
	enum TexTarget
	{
	TT_TEXTURE_1D		      = 0x0DE0,
	TT_TEXTURE_2D		      = 0x0DE1,
	TT_TEXTURE_3D		      = 0x806F, 
	TT_TEXTURE_RECTANGLE      = 0x84F5,
	TT_TEXTURE_CUBE_MAP       = 0x8513,
	TT_TEXTURE_2D_MULTISAMPLE = 0x9100,
	TT_SAMPLER_CUBE_MAP_ARRAY = 0x900C,
	
	
	TT_TEXTURE_CUBE_MAP_POSITIVE_X_ARB = 0x8515,
	TT_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB = 0x8516,
	TT_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB = 0x8517,
	TT_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB = 0x8518,
	TT_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB = 0x8519,
	TT_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB = 0x851A
	};
	
	
	enum TexGenMode
	{
	TGM_NONE			= 0,
	TGM_EYE_LINEAR		= 0x2400,
    TGM_OBJECT_LINEAR	= 0x2401,
	TGM_SPHERE_MAP		= 0x2402,
	TGM_NORMAL_MAP		= 0x8511,
	TGM_REFLECTION_MAP	= 0x8512
	};
	

	

enum PixelFormat
{
	PF_DEPTH						= 0x1902,
	PF_RED							= 0x1903,
	PF_GREEN						= 0x1904,
	PF_BLUE							= 0x1905,
	PF_ALPHA						= 0x1906,
	PF_RGB							= 0x1907,
	PF_RGBA							= 0x1908,
	PF_RGB8                         = 0x8051,
	PF_RGBA8                        = 0x8058,
	PF_LUMINANCE					= 0x1909,
	PF_LUMINANCE_ALPHA				= 0x190A,
	PF_BGR_EXT                      = 0x80E0,
	PF_BGRA_EXT                     = 0x80E1

	
};

enum TextureInternalFormat
{
	
	TIF_ALPHA8				        = 0x803C,
	TIF_ALPHA_FLOAT16		        = 0x881C,
	TIF_ALPHA_FLOAT32		        = 0x8816,
    TIF_LUMINANCE8			        = 0x8040,
	TIF_LUMINANCE_FLOAT16	        = 0x881E,
	TIF_LUMINANCE_FLOAT32	        = 0x8818,
    TIF_LUMINANCE8_ALPHA8			= 0x8045,
    TIF_LUMINANCE_ALPHA_FLOAT16		= 0x881F,
	TIF_LUMINANCE_ALPHA_FLOAT32		= 0x8819,
	TIF_INTENSITY8                  = 0x804B,
    TIF_INTENSITY_FLOAT16           = 0x881D,
	TIF_INTENSITY_FLOAT32           = 0x8817,
    TIF_RGB8                        = 0x8051,
	TIF_RGB_FLOAT16                 = 0x881B,
	TIF_RGB_FLOAT32                 = 0x8815,
    TIF_RGBA8                       = 0x8058,
    TIF_RGBA_FLOAT16                = 0x881A,
	TIF_RGBA_FLOAT32                = 0x8814,
	
    
	TIF_COMPRESSED_RGB_S3TC_DXT1_EXT  = 0x83F0,
	TIF_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
	TIF_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
	TIF_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,

	TIF_DEPTH_COMPONENT16			= 0x81A5,
	TIF_DEPTH_COMPONENT24			= 0x81A6,
	TIF_DEPTH_COMPONENT32			= 0x81A7

};
PixelFormat GetTexturePixelFormat(TextureInternalFormat frmt);

	class ITexture
	{
	public:

		ITexture( int w, int h,TextureInternalFormat format, int mipLevels,TexType  t );
		virtual ~ ITexture(){};
	

		
		
		int              GetWidth()                 const {return  width;         }
		int              GetHeight()                const {return  height;        }
		PixelFormat      GetPixelFormat()           const { return pixelFormat;   }
		TextureInternalFormat GetInternFormat()     const { return internFormat;  }
		TexType          GetTextureType()           const { return type;          }
		int              GetLevels()                const { return levels;        }

		bool IsCompressed() const                 { return compresed;  }
		bool IsMipMap()     const                 { return mipmap;     }
		
		
		virtual   char * GetData()                { return data;       }
		
		unsigned GetTextureId() const             {return  id;         }
		
		void     SetMipMap(bool isMip)             {mipmap = isMip;}
		
		
		void	SetSampler(gname::Sampler *smp)     { sampler = smp;  }

	    void	SetTexGenModeS (TexGenMode gen) {	tModeS = gen; }
	    void	SetTexGenModeT (TexGenMode gen) {	tModeT = gen; }
	    void	SetTexGenModeR (TexGenMode gen) {	tModeR = gen; }
	    void	SetTexGenModeQ (TexGenMode gen) {	tModeQ = gen; }

		virtual void SetTexturePixFormat(TextureInternalFormat fmt)
		{
			internFormat = fmt;
			pixelFormat =  GetTexturePixelFormat(internFormat);
		}

		virtual void BildTexture(){}
	private:
		virtual bool Alloc()           = 0;
		virtual void CreateTexture ()  = 0;
		virtual void RealizeTexture()  = 0;

	public:
		virtual void ClearData()  { if(data!=0) delete  data; data = 0;}
		char * data;
	protected:
		int width;
		int height;
		PixelFormat pixelFormat;
		TextureInternalFormat internFormat;
	    
		unsigned    id;
		int         levels;
		int         texUnit;
		bool        mipmap;
		bool        compresed;
		int         size;
		
		
		
		bool        isMultiSample;
	
	
		Sampler *sampler;
		TexGenMode tModeS;
		TexGenMode tModeT;
		TexGenMode tModeR;
		TexGenMode tModeQ;
		TexType    type;
		int aniso;
	};

	
	

}
#endif